//
//  CJTopLineThreeCell.m
//  Boss
//
//  Created by admin on 2018/9/10.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJTopLineThreeCell.h"
#import "CJImageViewCollectionCell.h"
@interface CJTopLineThreeCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) IBOutlet UILabel *timeAndName;
@property (strong, nonatomic) IBOutlet UILabel *readCount;

@end
@implementation CJTopLineThreeCell

-(void)setBossLine:(CJBOSSHeadLine *)bossLine
{
    _bossLine = bossLine;
    
    self.titleLabel.text = bossLine.headlineTitle;
    self.readCount.text = [NSString stringWithFormat:@"%@阅读量",bossLine.headlinePageviews];
    
    [self.collectionView reloadData];
}






- (void)awakeFromNib {
    [super awakeFromNib];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=CGSizeMake((kScreenWidth-52)/3.0, (kScreenWidth-52)/3.0/109*72);
    //横向最小距离
    layout.minimumInteritemSpacing=5.0f;
    layout.minimumLineSpacing=5.0f;
    //cell距离上  左  下 右 的距离
    layout.sectionInset=UIEdgeInsetsMake(0, 0, 0, 10);
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [self.collectionView setCollectionViewLayout:layout];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"CJImageViewCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"CJImageViewCollectionCell"];
    
    
    
    
    // Initialization code
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray  *array = [self.bossLine.headlinePictureUrl componentsSeparatedByString:@","];
    return array.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CJImageViewCollectionCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"CJImageViewCollectionCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"CJImageViewCollectionCell" owner:nil options:nil].firstObject;
    }
    NSArray  *array = [self.bossLine.headlinePictureUrl componentsSeparatedByString:@","];
    
    NSString *str = array[indexPath.row];
    
    [cell.detailImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@!default",str]] placeholderImage:nil];
    
    return cell;
    
}









- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
